<?php
/**
 * <b>RUBIK IT Solution & Development ltd.</b>
 *
 * PROJECT		: Rubik Ultimate Framework
 * @version 	: 1.1
 * COPYRIGHT    : 2008
 * ------------------------------------------------------
 * 
 * Created on	:  Jul 7, 2008
 * 
 */

// no direct access
defined ( '_FW_EXEC' ) or die ( 'Restricted access' );

class AbstractPlugin extends Object {
	
	var $_params;
	var $_name;

	function __construct($pluginParam, $folderName) {
		if (!$pluginParam) {
			$pluginParam = new stdClass();
		}
		$this->_params = $pluginParam;
		$this->_name = $folderName;
	}
	
	/**
	 * Get Parameters of Plugin
	 *
	 * @param string $name - Name of Parameter
	 * @return value of Parameter
	 */
	function getParam($name, $default = null) {
		if ($default === null) {
			return $this->_params->$name;
		}
		
		$val = $this->_params->$name;
		if ($val === null) {
			return $default;
		}
		return $val;
	}
	
	/**
	 * Set parameter
	 *
	 * @param string $name
	 * @param string $value
	 */
	function setParam($name, $value) {
		$this->_params->$name = $value;
	}
	
	/**
	 * Set all params
	 *
	 * @param mix $arrayOrObject
	 */
	function setParams($arrayOrObject) {
		RubikHelper::setProperties($this->_params, $arrayOrObject);
	}
	
	/**
	 * Get the encoded param string
	 *
	 * @return string
	 */
	function getParamEncoded() {
		$params = serialize ( $this->_params );
		$params = base64_encode ( $params );
		return $params;
	}
	
	/**
	 * Function to check Plugin view or not
	 * Please implements if you want special treat
	 * NOTE: this function can be OVERRIDE for general perpose.
	 *
	 * @return true|false Plugin showed if return true
	 */
	function isActive() {
		return true;
	}
	
	/**
	 * run
	 * @abstract 
	 *
	 */
	function run(&$runtimeParams) {
		die ( "This function must be implement in the class: <b>" . get_class ( $this )."::". __FUNCTION__ . "</b>" );
	}
	
//	/**
//	 * Get hash value for creating cache.
//	 * NOTE: this function can be OVERRIDE for general perpose
//	 *
//	 */
//	function hash() {
//		$hash = $this->_name;
//		foreach ( $this->_params as $key => $value ) {
//			$hash .= "{$key}->{$value}";
//		}
//		
//		return md5 ( $hash );
//	}
	
	/**
	 * Get the plugin name of current plugin
	 *
	 * @return string
	 */
	function getName() {
		return $this->_name;
	}
	
}
?>